<?php
	include('include/configs.inc.php');

	if(!empty($_POST['token'])) {
		$nom = $_POST['nom'];
		$prenom = $_POST['prenom'];
		$email = $_POST['email'];
		$password = $_POST['password'];
		$code = $_POST['code'];
		$pays = $_POST['pays'];
		$ville = $_POST['ville'];
		$adresse = $_POST['adresse'];
		$confirmation = $_POST['confirmation'];
		$error = '';
		
		if($password != $confirmation) {
			$error = "Le mot de passe et la confirmation sont diff&eacute;rents !";
		}
		
		if(empty($nom) || empty($prenom) || empty($email)) {
			$error .= "<br/>Tout les champs sont obligatoires sauf le mot de passe, merci de tous les remplir !";
		}
		
		if($error == '') {
			$pass = '';
		
			if(!empty($password)) {
				$pass = ", password=SHA1('".$password."')";
			}
		
			$sql = "UPDATE user SET nom='".$nom."', prenom='".$prenom."', email='".$email."', zip_code='".$code."', ville='".$ville."', pays='".$pays."', adresse='".$adresse."'".$pass." WHERE id=".$_SESSION['UID'];
			
			if($connect->query($sql)) {
				$message = "Vos donn&eacute;es ont &eacute;t&eacute; mise &agrave; jours !";
			} else {
				echo $error = $connect->error;
			}
		}
	}
	
	$sql1 = "SELECT * FROM user WHERE id=".$_SESSION['UID'];
	$user = $connect->query($sql1);
	
	include('template/Site_profil.html');
?>